package agent.configuration.rag;



import agent.componet.tool.FileTool;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.model.dashscope.QwenChatModel;
import dev.langchain4j.rag.DefaultRetrievalAugmentor;
import dev.langchain4j.rag.RetrievalAugmentor;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.rag.query.transformer.CompressingQueryTransformer;
import dev.langchain4j.rag.query.transformer.QueryTransformer;
import dev.langchain4j.service.AiServices;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@RequiredArgsConstructor
@Configuration
public class AiAssistantManager {


    // 召回引擎  （分片 索引 召回 重排）
private final ContentRetriever contentRetriever;

private final QwenChatModel qwenChatModel;

private final ChatMemory fileChatMemory;

private final FileTool fileTool;


@Bean(name = "queryAssistant")
public RagConfig.Assistant QueryAiServiceUsingFileTool(){


    QueryTransformer queryTransformer = new CompressingQueryTransformer(qwenChatModel);
    // The RetrievalAugmentor serves as the entry point into the RAG flow in LangChain4j.
    // It can be configured to customize the RAG behavior according to your requirements.
    // In subsequent examples, we will explore more customizations.

    RetrievalAugmentor retrievalAugmentor = DefaultRetrievalAugmentor.builder()
            .queryTransformer(queryTransformer)
            .contentRetriever(contentRetriever)
//--------------空缺-----------------------
            // 默认情况下，使用修改后的（keepAliveTime 为 1 秒而不是 60 秒）Executors.newCachedThreadPool()
//        DefaultRetrievalAugmentor.builder()
//        ...
//        .executor(executor)
            .build();

    return AiServices.builder(RagConfig.Assistant.class)
            .chatLanguageModel(qwenChatModel)
            .retrievalAugmentor(retrievalAugmentor)
            .chatMemory(fileChatMemory)
            .tools(fileTool)
            .build();
}




}
